<template>
  <div class="retailmember">
    <van-pull-refresh v-model="refreshing" @refresh="OnRefresh">
      <van-list
        v-model:loading="loading"
        :finished="finished"
        finished-text="没有更多了"
        @load="OnLoad"
      >
        <div class="list">
          <div class="item" v-for="item in list" v-bind:key="item.id">
            <div class="left">
              <div class="img">
                <img :src="item.avatar_cdn" />
              </div>
              <div class="content">
                <div class="nickname">{{ item.nickname }}</div>
                <div class="tel">{{ item.mobile }}</div>
              </div>
            </div>
            <div class="right">{{ item.createtime_text }}</div>
          </div>

          <van-back-top :bottom="'80'" />
        </div>
      </van-list>
    </van-pull-refresh>
  </div>
</template>

<script setup>
const { proxy } = getCurrentInstance();

// 用户信息
const business = proxy.$business;
// 分销会员数据
const list = ref([]);
// 数据总条数
const ListCount = ref(0);
// 刷新状态
const refreshing = ref(false);
// 懒加载状态
const loading = ref(false);
// 加载状态
const finished = ref(false);
// 当前页
const page = ref(1);

// 下拉刷新方法
const OnRefresh = async () => {
  finished.value = false;
  page.value = 1;
  list.value = [];
  loading.value = true;
  refreshing.value = true
//   setTimeout(OnLoad,1500);
};

const OnLoad = async () => {
    
  if (refreshing.value) {
    refreshing.value = false;
  }
  let params = {
    busid: business.value.id,
    page: page.value,
  };

  let result = await proxy.$http.post({
    url:'sale/business',
    params
  })

  loading.value = false;

  if(result.code === 1){
    list.value = list.value.concat(result.data.list)
    ListCount.value = result.data.count

    if(list.value.length >= ListCount.value){
        finished.value = true;
        return false;
    }

    page.value +=1
  }else{
    finished.value = true
    proxy.$fail(result.msg)
  }
};
</script>

<style scoped>
@import url("/assets/css/SaleBusiness.css");
</style>